package Engine;

import java.io.IOException;
import javax.swing.JOptionPane;

public class Engine {

    public void Win7FirewallExceptionPort(String user, String exceptionName, String port) {
        
        String source = "C:\\Windows\\System32\\cmd.exe /C ";
        String DOS = "runas /user:" + user +" "
                + "\"netsh advfirewall firewall add rule "
                + "name=" + exceptionName + " "
                + "dir=in "
                + "action=allow "
                + "protocol=TCP "
                + "localport=" + port + "\"";
        String runtime = "rundll32 SHELL32.DLL,ShellExec_RunDLL ";
        String comando = source + DOS;
        try {
            Runtime.getRuntime().exec(runtime + comando);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }
    
    public void Win7CreateFoldersShared(String folders){        
        String refFolders = folders;        
        String source = "C:\\Windows\\System32\\cmd.exe /C ";
        String DOS = "mkdir c:\\" + refFolders;
        String runtime = "rundll32 SHELL32.DLL,ShellExec_RunDLL ";
        String comando = source + DOS;
        try {
            Runtime.getRuntime().exec(runtime + comando);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }    
    }
    
    public void Win7ShareFolderWithUsers(String folders, String user){    
        String refFolders = folders;        
        String source = "C:\\Windows\\System32\\cmd.exe /C ";
        String DOS = "net share "+ refFolders +"=c:\\"+ refFolders +" /grant:"+ user +",full";
        String runtime = "rundll32 SHELL32.DLL,ShellExec_RunDLL ";
        String comando = source + DOS;
        try {
            Runtime.getRuntime().exec(runtime + comando);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }        
    }
    
    public void Win7CreatUserDefault(String login, String newUser, String password){                   
        String source = "C:\\Windows\\System32\\cmd.exe /C ";
        String DOS = "runas /user:"+login+" \"net user "+newUser+" "+password+" /add\"";
        String runtime = "rundll32 SHELL32.DLL,ShellExec_RunDLL ";
        String comando = source + DOS;
        try {
            Runtime.getRuntime().exec(runtime + comando);
        } catch (IOException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }       
    }
}